/* Copyright 2001,2002,2003 NAH6 BV
 * All Rights Reserved
 *
 *  $Header: /var/lib/cvs/secphone/ui/ce/CPhoneDlg.h,v 1.16 2003/11/21 12:39:24 itsme Exp $
 *
 *
 */


// CPhoneDlg.h : header file
//

#if !defined(AFX_CPHONEDLG_H__69AE591F_CD85_40A9_9EED_71F80FA6D108__INCLUDED_)
#define AFX_CPHONEDLG_H__69AE591F_CD85_40A9_9EED_71F80FA6D108__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#include "UniButton.h"
#include "Label.h"
#include "VuMeter2.h"
#include "BitmapControl.h"
#include "InterfaceLayout.h"
//#include <afxext.h>
#include <string>
#include <vector>
#include <utility>      // pair
#include "stringutils.h"

#include "resource.h"


// using domodal has the problem that several objects need the window handle
// of the dialog before it is active.
//
//#define _USE_DOMODAL 1

/////////////////////////////////////////////////////////////////////////////
// CCPhoneDlg dialog

typedef std::pair<std::string,std::string> StringPair;
typedef std::vector<StringPair> StringPairVector;

// how long (ms) the answer key needs to be pressed before our window pops up.
#define ANSWERKEY_POPUP_DELAY 500

// how long (ms) the mute key needs to be released before we unmute
#define MUTEKEY_RELEASE_TIME 1000

#define SIGNALQUALITY_UPDATE_INTERVAL  5000
#define BATTERYLIFE_UPDATE_INTERVAL    5000
#define MACHINE_WATCHDOG_INTERVAL      5000


// how fast the timer is running, this needs to be fast for the CE version,
// because we have to poll the hardware keys there.
#ifdef _WIN32_WCE
#define DLG_TIMER_INTERVAL  50
#else
#define DLG_TIMER_INTERVAL  5000
#endif


class CCPhoneDlg : public CDialog
{
// Construction
public:
    CCPhoneDlg(CWnd* pParent = NULL);   // standard constructor

    void DrawBitmap( CPaintDC &dc, RECT &r, CBitmap &bmp );
    BOOL LoadInterface();

#ifndef _USE_DOMODAL
    bool PumpMessages();
#endif
    virtual BOOL PreTranslateMessage(MSG* pMsg);

    // calltype methods
    void SetCallType(int nCallType);

    // status message methods
    void InternalSetStatus(const std::string& state);
    void InternalSetStatus2(const std::string& state);
    void SetStatus(const std::string& state);
    void SetFinalStatus(const std::string& state);
    void SetSecureStatus(bool bStatus);

    void SetSignalNone(char *msg1, char *msg2);
    void SetSignalQuality(int quality, int min, int max);
    void SetBatteryLife(int percent);
    void SetRoundTripTime(int roundtriptime, int min, int max);

    // talk/end button methods
    void ResetMuteButton();
    void EnableTalkButton(bool bEnabled);
    void EnableHangupButton(bool bEnabled);

    // key signature methods
    void SetKeySignature(const std::string& signature, bool bIAmTheOriginator);
    void ClearKeySignature();

    // partner number methods
    void SetPartnerName(const std::string& number);
    void InternalSetPartnerName(const std::string& number);
    void SetNumber(const std::string& number);
    void ClearPartner();
    void SetPartnerUnknown();

    //void SelectNumber(const std::string& number);
    bool GetNumber(std::string& number);

    void SetUpDownToVolumeControl();
    void SetUpDownToScrollButtons();

    void HistoryScrollUp();
    void HistoryScrollDown();
    void AddToHistory(const std::string& number, const std::string& name);
    bool IsNumberFromHistory();

private:
    InterfaceLayout m_cLayout;

    CBitmap m_cBackground;

    CUniButton m_cButton_sigok;

    CUniButton m_cButton_menu;
    CUniButton m_cButton_mute;
    CUniButton m_cButton_back;

    CUniButton m_cButton_1;
    CUniButton m_cButton_2;
    CUniButton m_cButton_3;

    CUniButton m_cButton_4;
    CUniButton m_cButton_5;
    CUniButton m_cButton_6;

    CUniButton m_cButton_7;
    CUniButton m_cButton_8;
    CUniButton m_cButton_9;

    CUniButton m_cButton_star;
    CUniButton m_cButton_0;
    CUniButton m_cButton_pound;

    CUniButton m_cButton_callanswer;
    CUniButton m_cButton_hangup;

    CUniButton m_cButton_up;
    CUniButton m_cButton_down;

    CVuMeter2 m_cLineDelay;
    CVuMeter2 m_cCallType;      // not a vumeter, just 2 states, too lazy to make separate class.
    BitmapControl m_cSigarea;


    CVuMeter2 m_cSecureStatus;  // not a vumeter, just 2 states, too lazy to make separate class.
    CLabel m_cYoursig;
    CLabel m_cPartnersig;

    CLabel m_cStatus;           // overlaps with partnername
    CLabel m_cStatus2;          // overlaps with partnernumber

    CLabel m_cPartnername;
    CLabel m_cPartnernumber;

    CVuMeter2 m_cGsmsignal;
    CVuMeter2 m_cBatterlevel;

    BitmapControl m_cBigsig_background;

    CLabel m_cBigsig_yoursig;
    CLabel m_cBigsig_partnersig;
    
    UINT m_nButtonCheckTimer;
    UINT m_nAnswerKeyPressTime;
    UINT m_nMuteKeyReleasedTime;
    UINT m_nTimerEvents;

    bool m_bMutePressed;

    bool m_bUpdownHandlesVolume;

    StringPairVector m_numbers;
    size_t m_currentnumber;

    bool m_initialized;

    enum { SHOW_UNINITIALIZED, SHOW_STATUS, SHOW_STATUS2, SHOW_NUMBER, SHOW_SIGNATURE };

    int m_showState;

    bool m_bPartnerUnknown;
    bool m_bNoSignal;
    bool m_bShowingLargeSignature;

    std::string m_sStatus;

// Dialog Data
    //{{AFX_DATA(CCPhoneDlg)
    enum { IDD = IDD_CPHONE_DIALOG };
        // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA

    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CCPhoneDlg)
    public:
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL

    void DoPickup();
    void DoReject();
    void DoHangup();
    void DoMakeCall();
    void HandleHangupKey();
    void HandleAnswerKey();
    void HandleMutePressed();
    void HandleMuteReleased();

    // utilities to make dialog creation easy.
    void MakeButton(CUniButton& button, const RECT& position, int id, 
            int idMask, int idNormal, int idPressed, int idDisabled,
            CWnd* parent= NULL);
    void MakeCheckButton(CUniButton& button, const RECT& position, int id,
            int idMask, int idNormal, int idPressed, int idChecked, int idDisabled,
            CWnd* parent= NULL);
    void MakeKey(CUniButton& button, const RECT& position, char c, int idMask, int idNormal, int idPressed, int idDisabled);
    void MakeLabel(CWnd* parent, CLabel& label, const RECT& position, int fontsize, COLORREF background);
    void MakeGreyLabel(CWnd* parent, CLabel& label, const RECT& position, int fontsize);
    void MakeLightGreyLabel(CWnd* parent, CLabel& label, const RECT& position, int fontsize);
    void MakeWhiteLabel(CWnd* parent, CLabel& label, const RECT& position, int fontsize);

    // change display state
    void ShowNumber();
    void ShowSignature();
    void ShowStatus();
    void ShowStatus2();

// Implementation
protected:
    HICON m_hIcon;
    // Generated message map functions
    //{{AFX_MSG(CCPhoneDlg)
    virtual BOOL OnInitDialog();
    virtual void OnOK();
    virtual void OnCancel();
    afx_msg void OnPaint();
    afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
    afx_msg void OnDestroy();
    afx_msg void OnTimer(UINT nIDEvent);
    afx_msg void OnActivate( UINT nState, CWnd* pWndOther, BOOL bMinimized );
    //}}AFX_MSG

    void OnEditClear();
    void OnBack();

    afx_msg void OnButtonSignatureOk();
    afx_msg void OnButtonMenu();
    afx_msg void OnButtonMute();
    afx_msg void OnButtonCallanswer();
    afx_msg void OnButtonHangup();
    afx_msg void OnButtonUp();
    afx_msg void OnButtonDown();

    afx_msg LRESULT OnGetDefID(WPARAM wParam, LPARAM lParam);
    afx_msg LRESULT OnSpIpcMessage( WPARAM wParam, LPARAM lParam);
    afx_msg LRESULT OnHotKey( WPARAM wParam, LPARAM lParam);  
	afx_msg LRESULT OnKeyUp( WPARAM wParam, LPARAM lParam);    
    afx_msg LRESULT OnCommandLineAction(WPARAM wParam, LPARAM lParam);
    afx_msg LRESULT OnSPMakeCall(WPARAM wParam, LPARAM lParam);
    DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnMute();
	afx_msg void OnMenuSettings();
	afx_msg void OnMenuResetaudiosettings();
	afx_msg void OnMenuAbout();
	afx_msg void OnMenuExit();
};

//{{AFX_INSERT_LOCATION}}
// Microsoft eMbedded Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CPHONEDLG_H__69AE591F_CD85_40A9_9EED_71F80FA6D108__INCLUDED_)
